package com.clz.mycustomview

import android.content.Intent
import android.os.Bundle
import android.support.v4.app.FragmentActivity
import android.view.View
import com.clz.mycustomview.anim.ObjectAnimatorActivity
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import kotlinx.android.synthetic.main.activity_test.*


class TestActivity : FragmentActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)
        btn_baseView.setOnClickListener(this)
        btn_view_animation.setOnClickListener(this)
        btn_frame_animation.setOnClickListener(this)
        btn_object_animator.setOnClickListener(this)
        btn_window_manager.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when(v?.id){
            R.id.btn_baseView -> { startActivity(ViewPracticeActivity::class.java) }
            R.id.btn_view_animation -> { startActivity(ViewAnimationActivity::class.java) }
            R.id.btn_frame_animation -> { startActivity(FrameAnimationActivity::class.java) }
            R.id.btn_object_animator -> { startActivity(ObjectAnimatorActivity::class.java) }
            R.id.btn_window_manager -> {
                XXPermissions.with(this) // 申请安装包权限
                        //.permission(Permission.REQUEST_INSTALL_PACKAGES)
                        // 申请悬浮窗权限
                        //.permission(Permission.SYSTEM_ALERT_WINDOW)
                        // 申请通知栏权限
                        //.permission(Permission.NOTIFICATION_SERVICE)
                        // 申请系统设置权限
                        //.permission(Permission.WRITE_SETTINGS)
                        // 申请单个权限
                        .permission(Permission.SYSTEM_ALERT_WINDOW)
                        .request(object : OnPermissionCallback {
                            override fun onGranted(permissions: List<String>, all: Boolean) {
                                if (all) {
                                    startActivity(WindowMangerActivity::class.java)
                                } else {

                                }
                            }

                            override fun onDenied(permissions: List<String>, never: Boolean) {
                                if (never) {

                                    // 如果是被永久拒绝就跳转到应用权限系统设置页面
                                    XXPermissions.startPermissionActivity(this@TestActivity, permissions)
                                } else {

                                }
                            }
                        })
            }
        }
    }

    private fun startActivity(cls: Class<*>){
        startActivity(Intent(this,cls))
    }


}